//
//  DSYILCollectionViewCell.m
//  BLDMusics
//
//  Created by dllo on 16/3/18.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "DSYILCollectionViewCell.h"
#import "DSYCarouselModel.h"

#define HOLDER [UIImage imageNamed:@"recommend_header_placeholder.jpg"]

@interface DSYILCollectionViewCell ()

@property (nonatomic, retain) UIImageView *imgView;
@property (nonatomic, retain) UILabel *nameLabel;

@end

@implementation DSYILCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubviews];
    }
    return self;
}

- (void)creatSubviews {
    self.imgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_imgView];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _nameLabel.frame = CGRectMake(0, 0, 50, 25);
    _nameLabel.center = CGPointMake(self.contentView.center.x, self.contentView.frame.size.height - 15);
    _nameLabel.font = [UIFont systemFontOfSize:15.0f];
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    
    _imgView.frame = CGRectMake(0, 0, 25, 25);
    _imgView.center = CGPointMake(_nameLabel.center.x, CGRectGetMinY(_nameLabel.frame) - 20);
}

- (void)setSourceModel:(DSYCarouselModel *)sourceModel
{
    _sourceModel = sourceModel;
    
    [_imgView sd_setImageWithURL:[NSURL URLWithString:_sourceModel.picUrl] placeholderImage:HOLDER];
    _nameLabel.text = _sourceModel.name;
}

@end
